<template>
  <el-form-item
    :key="element.metaRefresh"
    :prop="element.field"
    :label="element.componentProps.label"
    :rules="element.componentProps.rules"
  >
    <el-select
      clearable
      v-model="element.componentProps.value"
      class="m-2"
      placeholder="请选择一条数据"
      size="large"
      @change="selectChange"
    >
      <el-option
        v-for="item in componentProps"
        :key="item.value"
        :label="item.label"
        :value="item.value"
      />
    </el-select>
  </el-form-item>
</template>

<script lang="ts">
import {
  defineComponent,
  inject,
  toRefs,
  watch,
  reactive,
  computed,
} from "vue";
import type { LowCodeImp } from "@/components/low-code/core/type";
export default defineComponent({
  name: "selectWidget",
  props: ["element"],
  setup(props) {
    const getLowCodeInstance = inject("getLowCodeInstance") as Function;
    const lowCode = getLowCodeInstance() as LowCodeImp;
    const { element } = toRefs(props);
    const componentProps = [
      { value: "Asia", label: "亚洲" },
      { value: "Europe", label: "欧洲" },
      { value: "North America", label: "北美洲" },
      { value: "South America", label: "南美洲" },
      { value: "Africa", label: "非洲" },
      { value: "Oceania", label: "大洋洲" },
      { value: "Antarctica", label: "南极洲" },
    ];

    const selectChange = () => {
      element.value.componentProps.onChangeEvents.map(async (code: any) => {
        await lowCode.eventCenterController.fire(code);
      });
    };

    return {
      element,
      componentProps,
      selectChange,
    };
  },
});
</script>

<style scoped>
.el-select {
  width: 100%;
}
</style>
